<?php
     
     header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
     header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header ("Cache-Control: no-cache, must-revalidate");
     header ("Pragma: no-cache");
     
     header("content-type: application/x-javascript; charset=tis-620");
    include_once('connection/connection.php');
     $data=$_GET['data'];
     $val=$_GET['val'];
	// $value=$_GET['value'];
	 
	 
	 if($data=='district')
	 {
         
		  echo "<select name='district' id='district' class='txt' onChange=\"change_factor('factor',this.value);return createDropdown('block',this,document.getElementById('multiDist'));\">\n";
          echo "<option value='0'>==== District ====</option>\n";
          $result=mysql_query("select DISTINCT district_id, district_name from tbl_lookup_location order by district_name");
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               echo "<option value=\"$id\">$name</option> \n" ;
          } 
		  ?>
		
		 </select>
		<?php	
	 }
	 
	 if($data=='factor')
	 {		
         $val2=$val;
         $val =$val; 
		$qr="SELECT population_factor FROM tbl_lookup_pop_factor WHERE district_id = '$val'";
		$res=mysql_query($qr);
		$row=mysql_fetch_array($res);
		$factor=$row['population_factor'];
		?>    
		<input type="hidden"  name="factor1" id="factor1" value="<?php echo $factor;?>" class="txt5" size=20 style="color:#FF0000">
       
	    <?php 
	 }
	 
	 if($data=='block')
	 {	
	 
	 	    $val=trim($val);
			$val=explode(" ",$val);
         	$val=implode(",",$val);
			echo "<input type=hidden name='muldist' id='muldist' value=$val>";	
         	echo "<select name='block' id='block' class='txt' onChange=\"return createDropdown('panchayat',this,document.getElementById('multiBlock'))\" >\n
         	<option value='0'>=====Block====</option>\n";
         	                        
         	$result=mysql_query("SELECT DISTINCT block_id, block_name, district_id from tbl_lookup_location where district_id IN($val)");
						 
         	while(list($id, $name, $dist)=mysql_fetch_array($result))
		 	{       
			   
				 echo "<option value=\"$id\">$name</option> \n";
				
         	}
			
			echo "</select>";	 	
	 }
	 
	if($data=='tehsil')
	{
	        $val=trim($val);
			$val=explode(" ",$val);
         	$val=implode(",",$val);	
		 echo "<input type=hidden name='mulTehsil' id='mulTehsil'>";	
		 echo "<select name='tehsil' id='tehsil' class='txt' onChange=\"return createDropdown('',this,document.getElementById('multiTehsil'));\">\n";
        echo"<option value='0'>=====Tehsil====</option>\n";
		   
		  $result1=mysql_query("SELECT DISTINCT census_subdistrict_code,census_subdistrict_name from tbl_lookup_location where district_id IN($val)");
		 while(list($id1, $name1)=mysql_fetch_array($result1))
		 {       
              echo "<option value=\"$id1\">$name1</option> \n";
			   $val2 .= $id1;
         }	 	
	     echo "</select>";
		 /*$valTehsil2 =  "<script language='javascript'>getvariable(" . $valTehsil . "); </script>";
		 echo "<input type=text name='mulTehsil' id='mulTehsil' value=$valTehsil2>";*/
	}
	
	 if ($data=='panchayat') 
	 {
		    $val=trim($val);
			$val=explode(" ",$val);
         	$val=implode(",",$val);	
		  echo "<input type=hidden name='mulblock' id='mulblock' value=$val>";
          echo "<select name='panchayat' id='panchayat' class='txt' onChange=\"return createDropdown('village',this,document.getElementById('multiPanchayat'))\" >\n
          <option value='0'>=Gram panchayat=</option>\n";
          $val2=$val;
		  $val =$val;
		  $q="SELECT DISTINCT panchayat_id, panchayat_name from tbl_lookup_location where block_id IN($val)";
		 // echo $q;
          $result=mysql_query($q);
          while(list($id, $name)=mysql_fetch_array($result))
		  {
               echo "<option value=\"$id\">$name</option> \n" ;
          }
		  echo "</select>";
	  }
	   
	 if ($data=='village') 
	  {
		    $val=trim($val);
			$val=explode(" ",$val);
         	$val=implode(",",$val);	
		 echo "<input type=hidden name='mulpanchayat' id='mulpanchayat' value=$val>";
         echo "<select  name='village' id='village' class='txt' onChange=\"changeFormId(this.form,'form_id',this.value);return createDropdown('habit',this,document.getElementById('multiVillage'));\" >\n
          <option value='0'>=====Village====</option>\n";
            $val2=$val;
         	$val =$val; 
		  $q="SELECT DISTINCT village_id, village_name,census_village_code from tbl_lookup_location where panchayat_id IN($val)";
          $result=mysql_query($q);
          while(list($id, $name,$cvc)=mysql_fetch_array($result))
		  {
               echo "<option value=\"$id\">$name:$cvc</option> \n" ;
			 
          }
		   echo "</select>";
		}
		
		if ($data =='cvc') 
	  	{
		    $val=trim($val);
			$val=explode(" ",$val);
         	$val=implode(",",$val);	
			
		    $result=mysql_query("SELECT DISTINCT census_village_code,census_village_name from tbl_lookup_location where village_id IN($val)");
			$i=0;
         while(list($id1,$villname)=mysql_fetch_array($result))
		 { 
		  $cvcCode[$i]=$id1;
		  $i++;
		  }
		 
		 $cvcCode1=implode(",",$cvcCode);
		 ?>      
           <input type="text" name="cvc" value="<?php print_r($cvcCode1);?>" readonly class=txt size=15 style="color:#FF0000">
         <?php
		 }
		 if ($data =='population_benefited') 
	  	{
			 $val=trim($val);
			 $val=explode(" ",$val);
         	 $val=implode(",",$val);
			echo "<input type='hidden' name='mulvillage' id='mulvillage' value=$val>";
			$qr="SELECT SUM(total_population) AS total_population from tbl_lookup_location where village_id IN($val)";
			$res=mysql_query($qr);
			$row=mysql_fetch_array($res);
			$id2=$row['total_population'];
		   ?>      
		   <input type="text" name="population_benefited1" id="population_benefited1" value="<?php echo $id2;?>" readonly class="txt5" size="20" style="color:#FF0000">
         <?php 
		 }
		 
		 if ($data =='present_population') 
	  	{
			$val2=$val;
			$val = substr($val,0,10); ?>
         <input type="text" name="present_population1" id="present_population1" value="" readonly class="txt5" size="20" style="color:#FF0000" />
         <?php 
		 }
		 
		 
		if ($data =='form_id') 
	  	{
		 	$val2=$val;
			$val = substr($val,0,10);
			$dist=$_GET['dist'];
			$qid="UPDATE sequence SET id=LAST_INSERT_ID(id+1)";
			$rid = mysql_query($qid);
			$qryId="select id from sequence";
			$recId=mysql_query($qryId);
			$rowId=mysql_fetch_array($recId);
			$id=$rowId['id'];
			$form_id = substr($dist,0,4);
			$form_id = "Q1-RWSS-".$id;
			?>
			<input type="text" style="color:#FF0000" name="form_id" value="<?php echo $form_id; ?>" readonly class=txt size=20>
			<input type="hidden" style="color:#FF0000" name="id" value="<?php echo $id; ?>" readonly class=txt size=20>
		<?php }
		
			
		if ($data=='habit') 
	    {
		    $val=trim($val);
			$val1=explode(" ",$val);
         	$val=implode(",",$val1);
			$i=1;
			foreach($val1 as $villId)
			{
		 $q="SELECT DISTINCT habitation_code, habitation_name,village_id from tbl_lookup_location where village_id IN($villId) order by habitation_code";
          
          $result=mysql_query($q);
		  if(!($result))
		  {
		  echo "";
		  }else{
		  $num_habit = mysql_num_rows($result);
		  echo"<table>";
		   $j=1;
		  while(list($id, $name,$villageId)=mysql_fetch_array($result))
		  {
			 ?>
			 <tr>
				<td width="22%" align="center"><font id=habit>
					<input type="text" name="name_habi<?php echo $i;?>" id="name_habi<?php echo $i;?>"value="<?php echo ucwords(strtolower($name));?>" class="txt7" readonly></font>
				</td>
				<td width="15%" align="left"><font id=habit_code>
					<input type="text" name="habi_code<?php echo $i;?>" id="habi_code<?php echo $i;?>"value="<?php echo $id;?>" class="txt7" readonly></font>
				</td>
				<td align="center" width="4%"><input type="text" name="type_habit<?php echo $i;?>" id="type_habit<?php echo $i;?>" value="<?php if($j==1){ echo "MH"; } else { echo "OH"; } ?>" size="2" class="txt_1" readonly/></td>
				<td width="18%" align="center">
					<input type="radio" name="status<?php echo $i;?>" id="status<?php echo $i;?>" value="Existing" checked onClick="setEnable(this.value,<?php echo $i; ?>)"><font style="font-size: 8.5pt" face="Verdana" color="#000000">A</font>
					<input type="radio" name="status<?php echo $i;?>" id="status<?php echo $i;?>" onClick="setReadOnly(this.value,<?php echo $i; ?>)"value="NON TRACABLE"><font style="font-size: 8.5pt" face="Verdana" color="#000000">NA</font></p>
				</td>
			</tr>
			<?php
			   $i++;$j++;
          }  
		  echo "<input type='hidden' name='habcount' id='habcount' value=".$num_habit."></table>"; 
     }
	 }
	 } 
?>